Skip to content

Retain submitted input in acceptPost exercises#1477

Merged
ihalaij1 merged 1 commit into
apluslms:masterfrom
tamma1:retain-submitted-input
Oct 14, 2025
Merged

Retain submitted input in acceptPost exercises#1477
ihalaij1 merged 1 commit into
apluslms:masterfrom
tamma1:retain-submitted-input

Conversation

@tamma1
Copy link
Copy Markdown
Contributor

@tamma1 tamma1 commented Aug 29, 2025

Description

What?

Retain the submitted input value in the input field after submission in exercises defined with view_type: access.types.stdasync.acceptPost.

Why?

Students want to easily tweak their submission.

How?

When the exercise is reloaded, insert the last submitted input into the input field.

Fixes #1475

Testing

Remember to add or update unit tests for new features and changes.

What type of test did you run?

  • Accessibility test using the WAVE extension.
  • Django unit tests.
  • Selenium tests.
  • Other test. (Add a description below)
  • Manual testing.

I tested that the last submission persists in the input field after submission and after page refresh. This was tested also with exercises that have multiple input fields in the O1 course.

Did you test the changes in

  • Chrome
  • Firefox
  • This pull request cannot be tested in the browser.

Think of what is affected by these changes and could become broken

Translation

Programming style

  • Did you follow our style guides?
  • Did you use Python type hinting in all functions that you added or edited? (type hints for function parameters and return values)

Have you updated the README or other relevant documentation?

  • documents inside the doc directory.
  • README.md.
  • Aplus Manual.
  • Other documentation (mention below which documentation).

Is it Done?

  • Reviewer has finished the code review
  • After the review, the developer has made changes accordingly
  • Customer/Teacher has accepted the implementation of the feature

Clean up your git commit history before submitting the pull request!

@jkotimak jkotimak moved this to Under review in A+ sprints Sep 23, 2025
@jkotimak jkotimak requested a review from murhum1 September 23, 2025 10:48
@ihalaij1 ihalaij1 requested a review from Copilot October 10, 2025 09:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables retention of submitted input values in acceptPost exercises, allowing students to easily modify their previous submissions. The implementation detects acceptPost exercises by checking for textareas without fieldsets and fills them with the last submission data on page load.

  • Added detection logic to identify acceptPost exercises based on textarea and fieldset presence
  • Extended the loadLastSubmission function to support filling input fields with previous submission data
  • Updated the CSS selector for last submission links to use the correct navbar class

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 380 to +384
if (exercise.active_element) {
exercise.loadLastSubmission($(data));
} else if (hasTextarea && !hasFieldset) { // Identify acceptPost exercises
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic to identify acceptPost exercises using hasTextarea && !hasFieldset is fragile and could incorrectly classify other exercise types. Consider using a more explicit identifier such as a data attribute or exercise type property to reliably distinguish acceptPost exercises.

Suggested change
if (exercise.active_element) {
exercise.loadLastSubmission($(data));
} else if (hasTextarea && !hasFieldset) { // Identify acceptPost exercises
const exerciseType = exercise.element.data('exercise-type');
if (exercise.active_element) {
exercise.loadLastSubmission($(data));
} else if (exerciseType === 'acceptPost') { // Identify acceptPost exercises explicitly

Copilot uses AI. Check for mistakes.
Comment on lines +901 to +903
textareas.each(function(index) {
$(this).val(lastInputs[index]);
});
Copy link

Copilot AI Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No bounds checking when mapping submission data to textareas. If there are more textareas than submission data entries, or vice versa, this could result in undefined values or missed textareas. Add validation to ensure the arrays have matching lengths.

Suggested change
textareas.each(function(index) {
$(this).val(lastInputs[index]);
});
const minLen = Math.min(textareas.length, lastInputs.length);
// Set values for matching indices
textareas.each(function(index) {
if (index < lastInputs.length) {
$(this).val(lastInputs[index]);
} else {
// Clear extra textareas if there are more textareas than inputs
$(this).val('');
}
});
if (textareas.length !== lastInputs.length) {
// Optionally log a warning for debugging
if (window.console && console.warn) {
console.warn(
"Mismatch between number of textareas (" +
textareas.length +
") and submission data entries (" +
lastInputs.length +
")."
);
}
}

Copilot uses AI. Check for mistakes.
@ihalaij1 ihalaij1 force-pushed the retain-submitted-input branch from da67ed2 to f0e54a2 Compare October 14, 2025 09:17
@ihalaij1 ihalaij1 self-requested a review October 14, 2025 09:17
@ihalaij1 ihalaij1 self-assigned this Oct 14, 2025
Copy link
Copy Markdown
Contributor

@ihalaij1 ihalaij1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

I tested this and it works well.

@ihalaij1 ihalaij1 merged commit f2ee310 into apluslms:master Oct 14, 2025
8 of 9 checks passed
@github-project-automation github-project-automation Bot moved this from Under review to Done in A+ sprints Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

AcceptPost exercises clear inputs after submit

4 participants